import 'package:common/common.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:main_plugin/main_bloc.dart';

class MainPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  MainBloc _bloc;

  @override
  void initState() {
    super.initState();
    _bloc = MainBloc(MainState());
    _bloc.add(GetDataEvent());
  }

  @override
  void dispose() {
    super.dispose();
    _bloc.close();
  }

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<MainBloc, MainState>(
      builder: (context, state) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: const Text('Plugin example app'),
            ),
            body: Center(child: Text(state.word ?? "-")),
          ),
        );
        // return SafeArea(
        //     child: Center(
        //   child: Text(state.word ?? "-"),
        // ));
      },
      cubit: _bloc,
    );
  }
}
